import baseapi from '@/api/base'
import { getDataByParameter, getObjetInfoByPid, getCountByParameter, saveObjetInfo, deleteObjetInfo ,postInfo} from '@/utils/baserequest'
import storage from 'store'

const Base64 = require('js-base64').Base64

const api = {
  appContext: baseapi.biz,
  appAppId: baseapi.biz_app,
  appServer: 'invoice',
  //供应商端
  getByConditions_s: 'invoice/by/findLikeExample',
  getByConditionsCount_s: 'invoice/countLikeExample/',
  //医院端
  getByConditions: 'invoice/customer/by/findMoreLikeExample',
  getByConditionsCount: 'invoice/customer/countMoreLikeExample/',
  //供应商端
  getDetailByConditions_s: 'invoiceDetail/by/findMoreLikeExample',
  getDetailByConditionsCount_s: '/invoiceDetail/countMoreLikeExample/',
  //医院端
  getDetailByConditions: 'invoiceDetail/customer/by/findMoreLikeExample',
  getDetailByConditionsCount: '/invoiceDetail/customer/countMoreLikeExample/',
  //审核
  auditInfo:'invoice/review',
  //新增发票
  newInvoice:'settlement/newInvoice',
  //发票作废
  revokeInvoice:'/settlement/cancellationInvoice/',
  //发票确认
  confirmInvoice:'invoice/customerModify/'
}
export default api
//多条件查询
export function getByConditions_s(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getByConditions_s
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询列表条数
export function getByConditionsCount_s(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getByConditionsCount_s
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}
//多条件查询
export function getByConditions(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getByConditions
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询列表条数
export function getByConditionsCount(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getByConditionsCount
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}
//多条件查询明细
export function getDetailByConditions_s(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getDetailByConditions_s
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询明细列表条数
export function getDetailByConditionsCount_s(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getDetailByConditionsCount_s
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}
//多条件查询明细
export function getDetailByConditions(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getDetailByConditions
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询明细列表条数
export function getDetailByConditionsCount(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getDetailByConditionsCount
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}
//开发票
export function newInvoice(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.newInvoice + '/'
  const allheaders = appIdHeaders
  return saveObjetInfo(url, parameter, allheaders)
}
//新增和修改
export function saveInfo(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer + '/'
  const allheaders = appIdHeaders
  return saveObjetInfo(url, parameter, allheaders)
}
// 确认发票
export function confirmInvoice(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.confirmInvoice
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}
//删除记录
export function deleteInfo(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer + '/'
  const allheaders = appIdHeaders
  return deleteObjetInfo(url, parameter, allheaders)
}
// 通过pid得到信息通用请求:get请求
export function getInfoByPid(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer
  const allheaders = appIdHeaders
  return getObjetInfoByPid(url, parameter, allheaders)
}

// 审核
export function auditInfo(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.auditInfo
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}

// 发票作废
export function revokeInvoice(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.revokeInvoice
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}







